<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div id="app">
            姓名: <input type="text" v-model="value" />
            <p>姓:{{name[0] }}</p>
            <p>名:{{name[1] }}</p>
        </div>
        <script src="../vue.js"></script>
        <script>
            let vm = new Vue({
                el: '#app',
                data() {
                    return {
                        text: 'hello',
                        value: '',
                        x: '',
                        m: '',
                    };
                },
                computed: {
                    name() {
                        if (this.value.length == 2) {
                            this.x = this.value.substr(0, 1);
                            this.m = this.value.substr(1, 1);
                        } else if (this.value.length == 3) {
                            this.m = this.value.substr(1, 2);
                        } else if (this.value.length == 4) {
                            this.x = this.value.substr(0, 2);
                            this.m = this.value.substr(2, 2);
                        }
                        return [this.x, this.m];
                    },
                },
            });
        </script>
    </body>
</html>
